package com.chuanyang.driverh.mainorder.adapter;


import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chuanyang.driverh.R;
import com.chuanyang.driverh.base.BaseListAdapter;
import com.chuanyang.driverh.responseresult.WaybillDetailsData;

import java.util.List;

public class WayBillGoodInfoAdapter extends BaseListAdapter<WaybillDetailsData.WaybillDetailMsgListBean> {
    private List list;
    private Context context;
    private static GoodInfoHolder holder;
    private int count = 0;

    public WayBillGoodInfoAdapter(Context context, List<WaybillDetailsData.WaybillDetailMsgListBean> list) {
        super(context, list);
        this.list = list;
    }


    @Override
    public View getZkView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(getContext(), R.layout.order_item_goodinfo, null);
        }

        //获取每个条目要展示的数据
        WaybillDetailsData.WaybillDetailMsgListBean mitem = getItem(position);
        //获取Viewholder
        holder = GoodInfoHolder.getHolder(convertView);
        if(!TextUtils.isEmpty(mitem.getOrderItemNum()))
        {
            holder.tv_oredrinfo_itemnum.setText(mitem.getOrderItemNum());
        }
        else {
            holder.tv_oredrinfo_itemnum.setText("");

        }
        if(!TextUtils.isEmpty(mitem.getNoticeNo()))//发货通知单 有则显示
        {
            holder.tv_oredrinfo_outnum.setText(mitem.getNoticeNo());

        }
        else {
            holder.tv_oredrinfo_outnum.setText("");

        }
        holder.tv_oredrinfo_goodkinds.setText(mitem.getGoodsName());

        if(!TextUtils.isEmpty(mitem.getGoodsWeight()))
        {
            holder.tv_oredrinfo_weight.setText("重量："+mitem.getGoodsWeight() + "t");

        }
        else {
            holder.tv_oredrinfo_weight.setText("重量："+"");

        }
        if(!TextUtils.isEmpty(mitem.getGoodsMaterial()))//材质
        {
            holder.tv_oredrinfo_goodsMaterial.setText("材质："+mitem.getGoodsMaterial());

        }
        else {
            holder.tv_oredrinfo_goodsMaterial.setText("材质："+"");

        }
        if(!TextUtils.isEmpty(mitem.getGoodsStandard()))//规格
        {
            holder.tv_oredrinfo_standard.setText("规格："+mitem.getGoodsStandard());

        }
        else {
            holder.tv_oredrinfo_standard.setText("规格："+"");

        }
        if (TextUtils.isEmpty(mitem.getGoodsNum())) { //数量
            holder.tv_oredrinfo_goodcount.setText("数量：");

        }
        else {
            if (!TextUtils.isEmpty(mitem.getGoodsUnit())) {
                holder.tv_oredrinfo_goodcount.setText( "数量："+mitem.getGoodsNum() + mitem.getGoodsUnit());
            } else {
                holder.tv_oredrinfo_goodcount.setText(  "数量："+mitem.getGoodsNum());

            }
        }
        return convertView;
    }

    static class GoodInfoHolder {
        private TextView tv_oredrinfo_itemnum, tv_oredrinfo_outnum, tv_oredrinfo_goodkinds, tv_oredrinfo_goodcount, tv_oredrinfo_weight,tv_oredrinfo_standard,tv_oredrinfo_goodsMaterial;
        private LinearLayout ll_1,ll_2,ll_3;

        public GoodInfoHolder(View converView) {

            tv_oredrinfo_itemnum = (TextView) converView.findViewById(R.id.tv_oredrinfo_itemnum);//运单项次号
            tv_oredrinfo_outnum = (TextView) converView.findViewById(R.id.tv_oredrinfo_outnum);//发货通知单
            tv_oredrinfo_goodkinds = (TextView) converView.findViewById(R.id.tv_oredrinfo_goodkinds);
            tv_oredrinfo_goodcount = (TextView) converView.findViewById(R.id.tv_oredrinfo_goodcount);
            //   tv_carkinds = (TextView) converView.findViewById(R.id.tv_oredrinfo_carkinds);
            tv_oredrinfo_weight = (TextView) converView.findViewById(R.id.tv_oredrinfo_weight);
            tv_oredrinfo_goodsMaterial = (TextView) converView.findViewById(R.id.tv_oredrinfo_goodsMaterial);
            tv_oredrinfo_standard = (TextView) converView.findViewById(R.id.tv_oredrinfo_standard);
            ll_1= (LinearLayout)converView.findViewById(R.id.ll_1);
            ll_2= (LinearLayout)converView.findViewById(R.id.ll_2);
            ll_3= (LinearLayout)converView.findViewById(R.id.ll_3);
        }

        public static GoodInfoHolder getHolder(View converView) {
            holder = (GoodInfoHolder) converView.getTag();
            if (holder == null) {
                holder = new GoodInfoHolder(converView);
                converView.setTag(holder);
            }
            return holder;
        }
    }
}
